//
//  WSBaseRefreshListCustomTableViewController.m
//  WSFramework
//
//  Created by zhangcong on 2018/4/19.
//  Copyright © 2018年 zhangcong. All rights reserved.
//

#import "WSBaseRefreshListCustomTableViewController.h"
#import <WSEveryNoneView.h>
#import <WSConst.h>
@interface WSBaseRefreshListCustomTableViewController ()<WSViewActionProtocol>

@end

@implementation WSBaseRefreshListCustomTableViewController
- (void)didRequestComplete:(id)data {
    _dataArray = data;
    [super didRequestComplete:data];
    [self checkShowEmptyDataTipsView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [_dataArray count];
}

- (id)tableView:(UITableView *)tableView cellDataForRowAtIndexPath:(NSIndexPath *)indexPath {
    return _dataArray.count > indexPath.row ? [_dataArray objectAtIndex:indexPath.row] : nil;
}

-(void) checkShowEmptyDataTipsView
{
    if( [_dataArray count] == 0 )
    {
        [self showEmptyDataTipsViewWithString:[self emptyDataTipsContent] btnStr:[self emptyDataBtnContent]];
    }
    else if([self.tableView.tableFooterView isKindOfClass:[WSEveryNoneView class]])
    {
        [self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
    }
}

- (NSString*) emptyDataBtnContent {
    return @"";
}


-(UIView*) showEmptyDataCustomTipsView {
    return nil;
}

-(NSString*) emptyDataTipsContent
{
    return @"内容为空";
}

- (NSString*)emptyDataImageName {
    return kAppDefaultEmptyImageName;
}

-(void) showEmptyDataTipsViewWithString:(NSString*) content btnStr:(NSString*)btnStr
{
    UIView *view = [self showEmptyDataCustomTipsView];
    if ( view != nil ) {
        [self.tableView setTableFooterView:view];
    }
    else if ( content != nil)
    {
        //        [self.tableView setTableFooterView:[EveryNoneView everyNoneViewWith:content btnStr:btnStr myDelegate:self]];
        
#if 1
        [self.tableView setTableFooterView:[WSEveryNoneView everyNoneViewWithImage:[self emptyDataImageName] tipStr:content actionStr:btnStr myDelegate:self]];
#endif
    }
}

- (void)view:(UIView *)view didAction:(NSInteger)action data:(id)data {
    switch (action) {
        case kAction_EveryNoneBtn:
            [self emptyButtonAction];
            break;
            
        default:
            break;
    }
}

- (void)emptyButtonAction {
    NSLog(@"emptyButtonAction");
}

@end
